﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using UserControlLib.Models;

namespace UserControlLib.Converters
{
    public class ColorIndexConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Array array= parameter as Array;
            List<SolidColorBrush> colorList= array.OfType<SolidColorBrush>().ToList();
            if (value is int index)
            {
                // 确保索引在颜色列表范围内
                if (index >= 0 && index < colorList.Count)
                {
                    return colorList[index];
                }
                else
                {
                    return colorList[index/colorList.Count];
                }
            }
            // 如果索引超出范围，返回默认颜色
            return Brushes.Black;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
